package co.yixiang.yshop.module.pay.config;

import co.yixiang.yshop.framework.security.config.AuthorizeRequestsCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer;

/**
 * Pay 模块的 Security 配置
 * 确保支付回调接口不被拦截
 *
 * @author yshop
 */
@Configuration(proxyBeanMethods = false, value = "paySecurityConfiguration")
public class PaySecurityConfiguration {

    @Bean("payAuthorizeRequestsCustomizer")
    public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() {
        return new AuthorizeRequestsCustomizer() {

            @Override
            public void customize(AuthorizeHttpRequestsConfigurer<HttpSecurity>.AuthorizationManagerRequestMatcherRegistry registry) {
                // 支付回调通知接口，需要完全放行（微信支付、支付宝等第三方回调）
                registry.requestMatchers("/admin-api/pay/notify/**").permitAll()
                        .requestMatchers("/app-api/pay/notify/**").permitAll();
            }

        };
    }

}

